package com.lago.edu.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author stevejson
 */
@ControllerAdvice
public class GlobalExceptionResolver {

//    @ExceptionHandler(ArithmeticException.class)
//    public void handleException(ArithmeticException e, HttpServletResponse response) throws IOException {
//        response.getWriter().write(e.getMessage());
//    }


    @ExceptionHandler(ArithmeticException.class)
    public ModelAndView handleException(ArithmeticException e, HttpServletResponse response) throws IOException {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error");
        modelAndView.addObject("errorMsg", e.getMessage());
        return modelAndView;

    }
}
